import { IPSControlAttribute } from '../ipscontrol-attribute';
import { IPSControlLogic } from '../ipscontrol-logic';
import { IPSControlRender } from '../ipscontrol-render';
import { IPSDEGridColumn } from './ipsdegrid-column';
import { IPSLanguageRes } from '../../res/ipslanguage-res';
import { IPSSysCss } from '../../res/ipssys-css';
import { IPSSysImage } from '../../res/ipssys-image';
import { IPSSysPFPlugin } from '../../res/ipssys-pfplugin';
import { PSModelObjectImpl } from '../../psmodel-object-impl';

export class PSDEGridColumnImpl extends PSModelObjectImpl implements IPSDEGridColumn {
  get aggField(): string {
    return this.M.aggField;
  }

  get aggMode(): 'NONE' | 'SUM' | 'AVG' | 'MAX' | 'MIN' | 'USER' | 'USER2' | 'USER3' | 'USER4' {
    return this.M.aggMode || 'NONE';
  }

  get aggValueFormat(): string {
    return this.M.aggValueFormat;
  }

  get align(): 'LEFT' | 'CENTER' | 'RIGHT' {
    return this.M.align;
  }

  protected cappslanguageres: IPSLanguageRes | null = null;

  getCapPSLanguageRes(): IPSLanguageRes | null {
    if (this.cappslanguageres != null) return this.cappslanguageres;
    const value = this.M.getCapPSLanguageRes;
    if (value == null) {
      return null;
    }
    this.cappslanguageres = this.getPSModel4('res.IPSLanguageRes', value, 'getCapPSLanguageRes') as IPSLanguageRes;
    return this.cappslanguageres;
  }

  get capPSLanguageRes(): IPSLanguageRes | null {
    return this.getCapPSLanguageRes();
  }

  getCapPSLanguageResMust(): IPSLanguageRes {
    const value = this.getCapPSLanguageRes();
    if (value == null) {
      throw new Error('未指定标题语言资源');
    }
    return value;
  }

  get caption(): string {
    return this.M.caption;
  }

  protected cellpssyscss: IPSSysCss | null = null;

  getCellPSSysCss(): IPSSysCss | null {
    if (this.cellpssyscss != null) return this.cellpssyscss;
    const value = this.M.getCellPSSysCss;
    if (value == null) {
      return null;
    }
    this.cellpssyscss = this.getPSModel4('res.IPSSysCss', value, 'getCellPSSysCss') as IPSSysCss;
    return this.cellpssyscss;
  }

  get cellPSSysCss(): IPSSysCss | null {
    return this.getCellPSSysCss();
  }

  getCellPSSysCssMust(): IPSSysCss {
    const value = this.getCellPSSysCss();
    if (value == null) {
      throw new Error('未指定单元格样式对象');
    }
    return value;
  }

  get codeName(): string {
    return this.M.codeName;
  }

  get columnStyle(): string {
    return this.M.columnStyle;
  }

  get columnType(): 'DEFGRIDCOLUMN' | 'UAGRIDCOLUMN' | 'GROUPGRIDCOLUMN' {
    return this.M.columnType;
  }

  get dataItemName(): string {
    return this.M.dataItemName;
  }

  get dynaModelFilePath(): string {
    return this.M.dynaModelFilePath;
  }

  get excelCaption(): string {
    return this.M.excelCaption;
  }

  protected headerpssyscss: IPSSysCss | null = null;

  getHeaderPSSysCss(): IPSSysCss | null {
    if (this.headerpssyscss != null) return this.headerpssyscss;
    const value = this.M.getHeaderPSSysCss;
    if (value == null) {
      return null;
    }
    this.headerpssyscss = this.getPSModel4('res.IPSSysCss', value, 'getHeaderPSSysCss') as IPSSysCss;
    return this.headerpssyscss;
  }

  get headerPSSysCss(): IPSSysCss | null {
    return this.getHeaderPSSysCss();
  }

  getHeaderPSSysCssMust(): IPSSysCss {
    const value = this.getHeaderPSSysCss();
    if (value == null) {
      throw new Error('未指定头部样式对象');
    }
    return value;
  }

  get memo(): string {
    return this.M.memo;
  }

  get name(): string {
    return this.M.name;
  }

  get noPrivDisplayMode(): 1 | 2 {
    return this.M.noPrivDisplayMode;
  }

  protected pscontrolattributes: IPSControlAttribute[] | null = null;

  getPSControlAttributes(): IPSControlAttribute[] | null {
    if (this.pscontrolattributes == null) {
      this.pscontrolattributes = this.fillChildListModel(this.M.getPSControlAttributes, 'control.IPSControlAttribute') as IPSControlAttribute[];
    }
    return this.pscontrolattributes;
  }

  get psControlAttributes(): IPSControlAttribute[] | null {
    return this.getPSControlAttributes();
  }

  findPSControlAttribute(objKey: any): IPSControlAttribute | null {
    return this.getPSModel5('control.IPSControlAttribute', this.getPSControlAttributes(), objKey) as IPSControlAttribute;
  }

  protected pscontrollogics: IPSControlLogic[] | null = null;

  getPSControlLogics(): IPSControlLogic[] | null {
    if (this.pscontrollogics == null) {
      this.pscontrollogics = this.fillChildListModel(this.M.getPSControlLogics, 'control.IPSControlLogic') as IPSControlLogic[];
    }
    return this.pscontrollogics;
  }

  get psControlLogics(): IPSControlLogic[] | null {
    return this.getPSControlLogics();
  }

  findPSControlLogic(objKey: any): IPSControlLogic | null {
    return this.getPSModel5('control.IPSControlLogic', this.getPSControlLogics(), objKey) as IPSControlLogic;
  }

  protected pscontrolrenders: IPSControlRender[] | null = null;

  getPSControlRenders(): IPSControlRender[] | null {
    if (this.pscontrolrenders == null) {
      this.pscontrolrenders = this.fillChildListModel(this.M.getPSControlRenders, 'control.IPSControlRender') as IPSControlRender[];
    }
    return this.pscontrolrenders;
  }

  get psControlRenders(): IPSControlRender[] | null {
    return this.getPSControlRenders();
  }

  findPSControlRender(objKey: any): IPSControlRender | null {
    return this.getPSModel5('control.IPSControlRender', this.getPSControlRenders(), objKey) as IPSControlRender;
  }

  protected pssysimage: IPSSysImage | null = null;

  getPSSysImage(): IPSSysImage | null {
    if (this.pssysimage != null) return this.pssysimage;
    const value = this.M.getPSSysImage;
    if (value == null) {
      return null;
    }
    this.pssysimage = this.getPSModel4('res.IPSSysImage', value, 'getPSSysImage') as IPSSysImage;
    return this.pssysimage;
  }

  get psSysImage(): IPSSysImage | null {
    return this.getPSSysImage();
  }

  getPSSysImageMust(): IPSSysImage {
    const value = this.getPSSysImage();
    if (value == null) {
      throw new Error('未指定头部图片对象');
    }
    return value;
  }

  protected renderpssyspfplugin: IPSSysPFPlugin | null = null;

  getPSSysPFPlugin(): IPSSysPFPlugin | null {
    if (this.renderpssyspfplugin != null) return this.renderpssyspfplugin;
    const value = this.M.getPSSysPFPlugin;
    if (value == null) {
      return null;
    }
    this.renderpssyspfplugin = this.getPSModel4('res.IPSSysPFPlugin', value, 'getPSSysPFPlugin') as IPSSysPFPlugin;
    return this.renderpssyspfplugin;
  }

  get psSysPFPlugin(): IPSSysPFPlugin | null {
    return this.getPSSysPFPlugin();
  }

  getPSSysPFPluginMust(): IPSSysPFPlugin {
    const value = this.getPSSysPFPlugin();
    if (value == null) {
      throw new Error('未指定列前端扩展插件');
    }
    return value;
  }

  get userCat(): string {
    return this.M.userCat;
  }

  get userTag(): string {
    return this.M.userTag;
  }

  get userTag2(): string {
    return this.M.userTag2;
  }

  get userTag3(): string {
    return this.M.userTag3;
  }

  get userTag4(): string {
    return this.M.userTag4;
  }

  get width(): number {
    return this.M.width;
  }

  get widthUnit(): 'PX' | 'STAR' {
    return this.M.widthUnit;
  }

  get enableRowEdit(): boolean {
    return this.M.enableRowEdit != null ? this.M.enableRowEdit : false;
  }

  get enableSort(): boolean {
    return this.M.enableSort;
  }

  get hiddenDataItem(): boolean {
    return this.M.hiddenDataItem != null ? this.M.hiddenDataItem : false;
  }

  get hideDefault(): boolean {
    return this.M.hideDefault != null ? this.M.hideDefault : false;
  }

  get cls(): string {
    return 'PSDEGridColumnImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'control.IPSControlItem' || cls == 'control.grid.IPSDEGridColumn') return true;
    return super.instanceof(cls);
  }
}
